/**
 * Created by trisatria on 3/5/14.
 */
//check login
$(document).on('click','#btn_log', function(){
    $.mobile.loading('show');
    var activePage = $.mobile.activePage[0].id;
    var log_email = $("#"+activePage+" #log_email").val();
    var log_password = $("#"+activePage+" #log_pass").val();
    if(log_email != '' && log_password!= ''){
        //alert(log_email+" " + log_password);
        $.ajax({
            url: _host + 'user/login',
            type: 'POST',
            data: {username: log_email , password: log_password }
        }).done(function(data){
            $.mobile.loading('hide');
            var j_data = $.parseJSON(data);
            if(j_data['result'] == true){
                //objet
                var j_user = j_data['user_info'];
                $.session.set("logged",JSON.stringify(j_user));
                checklogin();
            }else{
                alert('Sai Tên Đăng Nhập Hoặc Mật Khẩu');
            }
        });
    }else{
        $.mobile.loading('hide');
    }
});


//
////  Uncomment the line below to store the Facebook token in localStorage instead of sessionStorage
////  openFB.init({appId: 'YOUR_FB_APP_ID', tokenStore: window.localStorage});
//
//window.fbAsyncInit = function () {
//    FB.init({
//        appId: '345700865584560', // replace your app id here
//        status: true,
//        cookie: true,
//        xfbml: true
//    });
//};
//(function (d) {
//    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
//    if (d.getElementById(id)) {
//        return;
//    }
//    js = d.createElement('script');
//    js.id = id;
//    js.async = true;
//    js.src = "//connect.facebook.net/en_US/all.js";
//    ref.parentNode.insertBefore(js, ref);
//}(document));
//
//function FBLogin() {
//    FB.login(function (response) {
//        if (response.authResponse) {
//            FB.api('/me', function(response) {
//
//                $.ajax({
//                    url: _host + 'login/fblogin',
//                    type: 'POST',
//                    data: {email: response.email , fbId :response.id }
//                }).done(function(data){
//                    var j_data = $.parseJSON(data);
//
//                    if(j_data['result'] == true){
//                        //objet
//                        var j_user = j_data['user_info'];
//                        $.session.set("logged",JSON.stringify(j_user));
//                        checklogin();
//                    }else{
//                        alert('Sai Tên Đăng Nhập Hoặc Mật Khẩu');
//                    }
//                });
//            });
//        }
//    }, {scope: 'email,user_likes,user_birthday,user_hometown,user_photos'});
//}